<template>
  <div class="risk">
    <div class="add" @click="add()">新增安全附件</div>
    <eagle-page-list 
      ref="eaglePageList"
      @bindData="bindData"
      :queryParams="queryParams"
      :url="url"
      :conditions="conditions"
      :pageSize="20"
      :isPage="false"
      >
      <template v-if="list.length>0" slot="list">
        <eagle-cell
          style="margin-top: 10px"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="warn_item">
          <div >
            <div class="warn_header">
              <div>{{ item.PartsName }}</div>
              <eagle-tag
                v-if="item.ExpireDays < 0"
                class="warn_tag"
                type="primary"
                >剩{{ Math.abs(item.ExpireDays) }}天</eagle-tag
              >
              <eagle-tag v-if="item.ExpireDays > 0" class="warn_tag" type="danger"
                >逾期{{ Math.abs(item.ExpireDays) }}天</eagle-tag
              >
            </div>
            <div class="dep_sort">
              <img src="@/assets/Images/AppIcon/icon_number.png" alt="" />
              <div>{{ item.PartsCode }}</div>
            </div>

            <div class="dep_sort" v-if="item.IsNeedCheck">
              <img
                src="@/assets/Images/AppIcon/icon_list_date.png"
                alt=""
              />
              <div>最近复检日期：{{ item.CheckDate || "无" }}</div>
            </div>
            <div class="dep_sort" v-if="item.IsNeedCheck">
              <img
                src="@/assets/Images/AppIcon/icon_list_date.png"
                alt=""
              />
              <div>下次复检日期：{{ item.NextCheckDate || "无" }}</div>
            </div>
            <div>该设备无需复检</div>
          </div>
          <eagle-divider />
          <div class="dep_btm">
            <div class="btm_item" @click="getFileDetail(item)">
              <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
              <div class="mr-20">查看文档</div>
            </div>
            <div class="btm_item" @click="getFile(item.ID)">
              <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
              <div class="mr-20">安全附件检验</div>
            </div>
            <div class="btm_item" @click="handleDelete(item)">
              <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
              <div class="mr-10">删除附件</div>
            </div>
          </div>
        </div>
        </eagle-cell>
      </template>
    </eagle-page-list>
  </div>
</template>

<script>
import { Dialog } from "vant";
export default {
  data() {
    return {
      url:"/EquEquipment/GetEquipmentSafeFile",
      conditions: {},
      queryParams: {
        equipmentCode: this.$route.query.equipmentCode,
      },
      list: [],
    };
  },
  created() {
  },
  methods: {
    bindData(data) {
      
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    add() {
      this.$router.push({
        path: "addEquFile",
        query: { equipmentCode: this.$route.query.equipmentCode },
      });
    },
    handleDelete(item) {
      Dialog.confirm({
        title: "询问",
        message: "确定要删除该条附件记录吗?",
      })
        .then(() => {
          // on confirm
          let _this = this;
          _this.$axios
          .get("/EquEquipment/DeleteEquSafeFile",{params:{ id: item.ID}})
          .then((res)=>{
            _this.$toast.success("删除成功！");
            _this.$refs.eaglePageList.search();
          })
        })
        .catch(() => {
          // on cancel
        });
    },
    getFile(Id){
     this.$router.push({
        path: "/Equipment/SafetyFileCheck",
        query: { equSafeFileID: Id },
      });
    },

    
    // 设备安全附件文档附件
    getFileDetail(item) {
      console.log('asdsadasda',item);
     this.$router.push({
        path: "/Equipment/SafetyEquipFileCheck",
        query: { id: item.ID },
      });
    },

    // 详情
    goDetail(ChemCode) {
      this.$router.push({
        path: "/Chemical/Detail",
        query: { ChemCode: ChemCode },
      });
    },
    // 编辑
    edit(ChemCode) {
      this.$router.push({
        path: "/Chemical/Edit",
        query: { ChemCode: ChemCode },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.van-cell {
  padding: 0 0;
}
.all_dep {
  background-color: #ffffff;
}
.warn_item {
  /*margin-bottom: 10px;*/
  padding: 10px 0 10px 10px;
  border-radius: 5px;
  position: relative;
}
.warn_header {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 10px;
  .warn_tag {
    position: absolute;
    right: -4px;
    top: 0;
    border-radius: 26.64rem 0 0 26.64rem;
  }
}
.dep_sort {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
